package com.hc.mybatis.generator.plugins.utils;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;

import java.util.Iterator;
import java.util.List;

public class CommentTools {

    public CommentTools() {
    }

    public static void addFieldComment(Field field, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        field.addJavaDocLine("/**");
        field.addJavaDocLine(" * 这是Mybatis Generator拓展插件生成的属性(请勿删除).");
        sb.append(" * This field corresponds to the database table ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        field.addJavaDocLine(sb.toString());
        field.addJavaDocLine(" *");
        field.addJavaDocLine(" * @mbggenerated");
        field.addJavaDocLine(" * @author hc");
        field.addJavaDocLine(" * qq ");
        field.addJavaDocLine(" */");
    }

    public static void addInnerClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        innerClass.addJavaDocLine("/**");
        innerClass.addJavaDocLine(" * 这是Mybatis Generator拓展插件生成的类(请勿删除).");
        sb.append(" * This class corresponds to the database table ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        innerClass.addJavaDocLine(sb.toString());
        innerClass.addJavaDocLine(" *");
        innerClass.addJavaDocLine(" * @mbggenerated");
        innerClass.addJavaDocLine(" * @author hc");
        innerClass.addJavaDocLine(" * qq ");
        innerClass.addJavaDocLine(" */");
    }

    public static void addInnerEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        innerEnum.addJavaDocLine("/**");
        innerEnum.addJavaDocLine(" * 这是Mybatis Generator拓展插件生成的枚举(请勿删除).");
        sb.append(" * This class corresponds to the database table ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        innerEnum.addJavaDocLine(sb.toString());
        innerEnum.addJavaDocLine(" *");
        innerEnum.addJavaDocLine(" * @mbggenerated");
//        innerEnum.addJavaDocLine(" * @author hc");
//        innerEnum.addJavaDocLine(" * qq ");
        innerEnum.addJavaDocLine(" */");
    }

    public static void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        method.addJavaDocLine("/**");
        method.addJavaDocLine(" * 这是Mybatis Generator拓展插件生成的方法(请勿删除).");
        sb.append(" * This method corresponds to the database table ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" *");
        method.addJavaDocLine(" * @mbggenerated");
//        method.addJavaDocLine(" * @author hc");
//        method.addJavaDocLine(" * qq ");
        method.addJavaDocLine(" */");
    }

    public static void addGeneralMethodComment(Method method, String doc) {
        method.addJavaDocLine("/**");
        method.addJavaDocLine(" * " + doc);
        method.addJavaDocLine(" *");
        List<Parameter> parameterList = method.getParameters();
        Iterator var4 = parameterList.iterator();

        while (var4.hasNext()) {
            Parameter parameter = (Parameter) var4.next();
            String paramterName = parameter.getName();
            method.addJavaDocLine(" * @param " + paramterName);
        }

        method.addJavaDocLine(" */");
    }

    public static void addComment(XmlElement xmlElement) {
        xmlElement.addElement(new TextElement("<!--"));
        StringBuilder sb = new StringBuilder();
        sb.append("  WARNING - ");
        sb.append("@mbggenerated");
        xmlElement.addElement(new TextElement(sb.toString()));
        xmlElement.addElement(new TextElement("  这个节点为代码生成工具生成，请不要修改!"));
        xmlElement.addElement(new TextElement("  @author hc"));
        xmlElement.addElement(new TextElement("  @qq "));
        xmlElement.addElement(new TextElement("-->"));
    }

    public static void addInterfaceComment(Interface interf, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        interf.addJavaDocLine("/**");
        interf.addJavaDocLine(" * 这是Mybatis Generator拓展插件生成的接口(请勿删除).");
        sb.append(" * This class corresponds to the database table ");
        sb.append(introspectedTable.getFullyQualifiedTable());
        interf.addJavaDocLine(sb.toString());
        interf.addJavaDocLine(" *");
        interf.addJavaDocLine(" * @mbggenerated");
        interf.addJavaDocLine(" * @author hc");
        interf.addJavaDocLine(" * @qq ");
        interf.addJavaDocLine(" */");
    }

}
